import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
import "./assets/main.css";
import Moment from "moment";
import less from "less";

Vue.use(ElementUI);
Vue.use(less);

//components
import SideMenu from "@/components/common/SideMenu";

import EditButton from "./components/button/EditButton";
import DelButton from "./components/button/DelButton";
import AddButton from "./components/button/AddButton";
import BaseButton from "./components/button/BaseButton";

import CKEditorVue from "./components/CKEditorVue";
// import Editor from '@tinymce/tinymce-vue'
import Editor from "./components/Editor";

Vue.component("m-side-menu", SideMenu);
Vue.component("edit-button", EditButton);
Vue.component("del-button", DelButton);
Vue.component("add-button", AddButton);
Vue.component("base-button", BaseButton);
Vue.component("ck-editor", CKEditorVue);
Vue.component("editor", Editor);
// Vue.component('editor',Editor);

//script
import Config from "./script/config";
import HTTP from "./script/http";
import Utils from "./script/utils";
import User from "./script/user";
import Rule from "./script/rule";

Vue.prototype.$config = Config;
Vue.prototype.$http = HTTP;
Vue.prototype.$utils = Utils;
Vue.prototype.$user = User;
Vue.prototype.$rule = Rule;
Vue.prototype.$moment = Moment;

router.beforeEach((to, from, next) => {
  let _crossList = ["/login"];
  if (_crossList.indexOf(to.path) === -1) {
    if (!User.getToken()) {
      next({ path: "/login" });
    } else {
      next();
    }
  } else {
    next();
  }
});

Vue.config.productionTip = false;

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount("#app");
